package com.kaka.bus.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.kaka.bus.R;

/**
 * Created by OnionMac on 2018/7/9.
 */

public class SelfItemView extends CardView {

    private View mLine;
    private TextView mTitle;
    private TextView mValue;
    private boolean mShowLine;
    private String mName;

    public SelfItemView(@NonNull Context context) {
        this(context,null);
    }

    public SelfItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public SelfItemView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setCardElevation(1);
        setRadius(0);
        initView();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SelfItemView);
        mShowLine = a.getBoolean(R.styleable.SelfItemView_self_line,false);
        mName = a.getString(R.styleable.SelfItemView_self_title);
        mLine.setVisibility(mShowLine ? View.VISIBLE:View.GONE);

        mTitle.setText(mName);

        a.recycle();

    }

    public void setValue(String title,String value){
        mTitle.setText(title);
        mValue.setText(value);
    }

    public void setLineVisiable(boolean visiable){
        mLine.setVisibility(visiable ? View.VISIBLE:View.GONE);
    }

    private void initView() {
        View.inflate(getContext(), R.layout.item_self,this);

        mLine = findViewById(R.id.self_line);
        mTitle = findViewById(R.id.self_title);
        mValue = findViewById(R.id.self_value);
    }
}
